package cn.chiship.framework.third.biz.wxpub.controller;


import cn.chiship.framework.common.annotation.SystemOptionAnnotation;
import cn.chiship.framework.common.enums.BusinessTypeEnum;
import cn.chiship.sdk.framework.base.BaseService;
import cn.chiship.sdk.framework.base.BaseController;
import cn.chiship.sdk.core.base.BaseResult;
import cn.chiship.sdk.core.util.StringUtil;
import cn.chiship.sdk.core.base.constants.BaseConstants;
import cn.chiship.sdk.core.annotation.Authorization;
import javax.annotation.Resource;
import cn.chiship.framework.third.biz.wxpub.service.ThirdWechatArticleRelationConfigService;
import cn.chiship.framework.third.biz.wxpub.entity.ThirdWechatArticleRelationConfig;
import cn.chiship.framework.third.biz.wxpub.entity.ThirdWechatArticleRelationConfigExample;
import cn.chiship.framework.third.biz.wxpub.pojo.dto.ThirdWechatArticleRelationConfigDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.validation.Valid;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.beans.BeanUtils;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 素材关联配置控制层
 * 2022/9/17
 * @author lijian
 */
@RestController
@Authorization
@RequestMapping("/thirdWechatArticleRelationConfig")
@Api(tags = "素材关联配置")
public class ThirdWechatArticleRelationConfigController extends BaseController <ThirdWechatArticleRelationConfig,ThirdWechatArticleRelationConfigExample> {

    private static final Logger LOGGER = LoggerFactory.getLogger(ThirdWechatArticleRelationConfigController.class);

    @Resource
    private ThirdWechatArticleRelationConfigService thirdWechatArticleRelationConfigService;
    @Override
    public BaseService getService() {
        return thirdWechatArticleRelationConfigService;
    }

    @SystemOptionAnnotation(describe = "素材关联配置列表数据")
    @ApiOperation(value = "素材关联配置列表数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "keyword", value = "关键字",dataTypeClass =String.class, paramType = "query"),
    })
    @GetMapping(value = "/list")
    public ResponseEntity<BaseResult> list(@RequestParam(required = false, defaultValue = "", value = "keyword") String keyword) {
        ThirdWechatArticleRelationConfigExample thirdWechatArticleRelationConfigExample = new ThirdWechatArticleRelationConfigExample();
        //创造条件
        ThirdWechatArticleRelationConfigExample.Criteria thirdWechatArticleRelationConfigCriteria = thirdWechatArticleRelationConfigExample.createCriteria();
        thirdWechatArticleRelationConfigCriteria.andIsDeletedEqualTo(BaseConstants.NO);
        if (!StringUtil.isNullOrEmpty(keyword)) {
        }
        return super.responseEntity(BaseResult.ok(super.list(thirdWechatArticleRelationConfigExample)));
    }

    @SystemOptionAnnotation(option = BusinessTypeEnum.SYSTEM_OPTION_SAVE, describe = "保存素材关联配置")
    @ApiOperation(value = "保存素材关联配置")
    @PostMapping(value = "save")
    public ResponseEntity<BaseResult> save(@RequestBody @Valid ThirdWechatArticleRelationConfigDto thirdWechatArticleRelationConfigDto) {
        ThirdWechatArticleRelationConfig thirdWechatArticleRelationConfig = new ThirdWechatArticleRelationConfig();
        BeanUtils.copyProperties(thirdWechatArticleRelationConfigDto, thirdWechatArticleRelationConfig);
        return super.responseEntity(super.save(thirdWechatArticleRelationConfig));
    }

    @SystemOptionAnnotation(option = BusinessTypeEnum.SYSTEM_OPTION_UPDATE, describe = "更新素材关联配置")
    @ApiOperation(value = "更新素材关联配置")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键", dataTypeClass = String.class, paramType = "path", required = true)
    })
    @PostMapping(value = "update/{id}")
    public ResponseEntity<BaseResult> update(@PathVariable("id") String id, @RequestBody @Valid ThirdWechatArticleRelationConfigDto thirdWechatArticleRelationConfigDto) {
        ThirdWechatArticleRelationConfig thirdWechatArticleRelationConfig = new ThirdWechatArticleRelationConfig();
        BeanUtils.copyProperties(thirdWechatArticleRelationConfigDto, thirdWechatArticleRelationConfig);
        return super.responseEntity(super.update(id,thirdWechatArticleRelationConfig));
    }

    @SystemOptionAnnotation(option = BusinessTypeEnum.SYSTEM_OPTION_REMOVE, describe = "删除素材关联配置")
    @ApiOperation(value = "删除素材关联配置")
    @PostMapping(value = "remove")
    public ResponseEntity<BaseResult> remove(@RequestBody List<String> ids) {
        ThirdWechatArticleRelationConfigExample thirdWechatArticleRelationConfigExample = new ThirdWechatArticleRelationConfigExample();
        thirdWechatArticleRelationConfigExample.createCriteria().andIdIn(ids);
        return super.responseEntity(super.remove(thirdWechatArticleRelationConfigExample));
    }
}